public class Test {
	public static void main(String[] args) {
		String hashed = BCrypt.hashpw("111111", BCrypt.gensalt());

		System.out.println(hashed);

		// 产生因子12，默认10;django默认12

		hashed = BCrypt.hashpw("111111", BCrypt.gensalt(12));

		System.out.println(hashed);

		// Check that an unencrypted password matches one that has

		// previously been hashed

		if (BCrypt.checkpw("111111", hashed))

			System.out.println("It matches");

		else

			System.out.println("It does not match");

		/*
		 * django产生的password和一般的password略有不同
		 * 
		 * django的
		 * bcrypt$$2a$12$rfJm.0vyOBApZwdNS6P/yeewTSfB9v2WuzUSvmsaI0Xaho50WAaw2
		 * 
		 * 一般的 $2a$10$.G35312vqNmwvHlBp.Q4NeXhmBsTnvitJtZ3ASyw.z8VbnO1WVO9G
		 * $2a$12$hy2rjNmLIB6UooPnt3SEs.vTMFxgLD9x9rqdBsd.t18FA.QUZnOG.
		 * 
		 * django多了一个前缀bcrypt$ 这个前缀，django要用到
		 * 
		 * 两种方法
		 */

		// 第一种

		String django_nameString = "jack";
		String django_passwordString = "bcrypt$$2a$12$rfJm.0vyOBApZwdNS6P/yeewTSfB9v2WuzUSvmsaI0Xaho50WAaw2";

		String password = django_passwordString.substring(
				django_passwordString.indexOf('$') + 1,
				django_passwordString.length());

		System.out.println(password);

		if (BCrypt.checkpw(django_nameString, password))

			System.out.println("Jack matches");

		else

			System.out.println("Jack does not match");
		
		// 第二种，修改BCrypt.java中的checkpw源码

	}
}